package cn.lyw.usermessage.controller.controller;

import cn.common.beancopy.util.BeanCopierUtil;
import cn.common.restresult.util.RestResult;
import cn.common.restresult.util.ResultEnum;
import cn.lyw.usermessage.controller.dto.AddUserEncryptedDTO;
import cn.lyw.usermessage.controller.dto.EditUserEncryptedDTO;
import cn.lyw.usermessage.controller.dto.GetUserEncryptedDTO;
import cn.lyw.usermessage.controller.vo.GetUserEncryptedVO;
import cn.lyw.usermessage.service.bo.AddUserEncryptedBO;
import cn.lyw.usermessage.service.bo.EditUserEncryptedBO;
import cn.lyw.usermessage.service.bo.GetUserEncryptedBO;
import cn.lyw.usermessage.service.domain.GetUserEncryptedDO;
import cn.lyw.usermessage.service.service.UserEncryptedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lyw
 * @Description 用户密保接口
 * @Date 10:19 2021/7/17
 * @Param
 * @return
 */
@RestController
@RequestMapping("/userEncrypted")
public class UserEncryptedController {

    @Autowired
    private UserEncryptedService userEncryptedService;

    /**
     * @return
     * @Author lyw
     * @Description 查询用户密保接口
     * @Date 10:23 2021/7/17
     * @Param
     */
    @PostMapping("/getUserEncrypted")
    public RestResult<List<GetUserEncryptedVO>> getUserEncrypted(GetUserEncryptedDTO dto) {
        //转换类型
        GetUserEncryptedBO getUserEncryptedBO = BeanCopierUtil.copyObj(dto, GetUserEncryptedBO.class);
        //调用service中的查询方法
        List<GetUserEncryptedDO> userEncrypted = userEncryptedService.getUserEncrypted(getUserEncryptedBO);
        //判断是否查询到
        if (userEncrypted.isEmpty()) {
            return new RestResult(ResultEnum.SELECT_NULL);
        }
        //将返回值转为vo
        List<GetUserEncryptedVO> getUserEncryptedVOS = BeanCopierUtil.copyList(userEncrypted, GetUserEncryptedVO.class);
        return new RestResult<>(getUserEncryptedVOS);
    }


    /**
     * @return
     * @Author lyw
     * @Description 添加用户密保
     * @Date 10:48 2021/7/17
     * @Param
     */
    @PostMapping("/addUserEncrypted")
    public RestResult addUserEncrypted(AddUserEncryptedDTO dto) {
        //转换参数
        AddUserEncryptedBO addUserEncryptedBO = BeanCopierUtil.copyObj(dto, AddUserEncryptedBO.class);
        //调用service中的添加方法
        return userEncryptedService.addUserEncrypted(addUserEncryptedBO);
    }


    /**
     * @return
     * @Author lyw
     * @Description 修改密保
     * @Date 10:59 2021/7/17
     * @Param
     */
    @PostMapping("/editUserEncrypted")
    public RestResult editUserEncrypted(EditUserEncryptedDTO dto) {
        //转换参数
        EditUserEncryptedBO editUserEncryptedBO = BeanCopierUtil.copyObj(dto, EditUserEncryptedBO.class);
        //调用service中的添加方法
        return userEncryptedService.editUserEncrypted(editUserEncryptedBO);
    }


    /**
     * @return
     * @Author lyw
     * @Description 删除密保
     * @Date 11:02 2021/7/17
     * @Param
     */
    @PostMapping("/delUserEncrypted")
    public RestResult delUserEncrypted(String encryptedId) {
        //调用service中的添加方法
        return userEncryptedService.delUserEncrypted(encryptedId);
    }

}
